<admintpl file="header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Customer/index')}">客户列表</a></li>
			<li class="active"><a href="{:U('Customer/add')}">添加客户</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form" action="{:U('Customer/customer_post')}">
			<fieldset>
				<div class="control-group">
					<label class="control-label">客户姓名</label>
					<div class="controls">
						<input type="text" name="customer_name" required="required">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">手机号</label>
					<div class="controls">
						<input type="text" name="mobile" required="required">
					</div>
				</div>
				<div class="control-group" style="display: none">
					<label class="control-label">客户性别</label>
					<div class="controls">
						<input name="sex" type="radio" value="1" />男&nbsp;
						<input name="sex" type="radio" value="2" />女&nbsp;
						<input name="sex" type="radio" value="0" checked/>保密&nbsp;
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">客户类型</label>
					<div class="controls">
						<foreach name="customer_type_list" item="vo">
							    <input name="customer_type_id" type="radio" value="{$vo['id']}" required="required"/>&nbsp;&nbsp;{$vo['name']}&nbsp;（{$vo['memo']}）<br/>
						</foreach>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">账号状态</label>
					<div class="controls">
						<foreach name="customer_status_list" item="vo" >
						    <input name="status" type="radio" value="{$vo['key']}" disabled="disabled" <if condition="$vo['key'] eq '0'">checked</if>/>{$vo['value']}&nbsp;

                        </foreach>
					</div>
				</div>
                
				<div class="control-group time-limit">
					<label class="control-label">激活时间</label>
					<div class="controls">
						<input style="width:150px" id="active_time" type="date" name="active_time" value="" required="required"/>
					</div>
				</div>
				<div class="control-group time-limit">
					<label class="control-label">过期时间</label>
					<div class="controls">
						<input style="width:150px" id="expiration_time" type="date" name="expiration_time" value="" required="required"/>
					</div>
				</div>
			</fieldset>
			<div class="form-actions">
				<button type="submit" class="btn  btn-danger js-ajax-submit">{:L('ADD')}</button>
				<a class="btn" href="javascript:history.back(-1);">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
	    //初始化时间控件
	    var now = new Date() ;
	        
	    var nowYear = now.getFullYear() ; //年
	    var nowMonth = now.getMonth()+1<10?"0"+(now.getMonth()+1):now.getMonth() ; //月
	    var nowDay = now.getDate()<10?"0"+now.getDate():now.getDate() ; //日期
	        
	    var nowHour = now.getHours()<10?"0"+now.getHours():now.getHours() ; //时
	    var nowMinute = now.getMinutes()<10?"0"+now.getMinutes():now.getMinutes() ; //分
	        
	    var nowDate = nowYear+"-"+nowMonth+"-"+nowDay ;
	        
	    $("#active_time").val(nowDate) ;
	    $("#expiration_time").val(getNewDay(nowDate, 375));

        //日期加上天数得到新的日期  
//dateTemp 需要参加计算的日期，days要添加的天数，返回新的日期，日期格式：YYYY-MM-DD  
		function getNewDay(dateTemp, days) {  
		    var dateTemp = dateTemp.split("-");  
		    var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式    
		    var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);  
		    var rDate = new Date(millSeconds);  
		    var year = rDate.getFullYear();  
		    var month = rDate.getMonth() + 1;  
		    if (month < 10) month = "0" + month;  
		    var date = rDate.getDate();  
		    if (date < 10) date = "0" + date;  
		    return (year + "-" + month + "-" + date);  
		}
	</script>
	<script type="text/javascript">
        $("#active_time").change(function(){
        	var active_time     = $(this).val();
        	var expiration_time = getNewDay(active_time,375);
        	$("#expiration_time").val(expiration_time);
        })

        $('input[type=radio][name=status]').change(function() {
	        var status = $(this).val();
            if(status != 0){
                $(".time-limit").hide();
            }else{
            	$(".time-limit").show();
            }
        });

       $('input[type=radio][name=customer_type_id]').change(function(){
       	    var customer_type_id = $(this).val();
       	    var type_array       = new Array('2','3','4');
       	    var active_time      = $("#active_time").val();
       	   
       	    var expiration_time  = $.inArray(customer_type_id,type_array)>=0 ?  getNewDay(active_time,375) : getNewDay(active_time,36500);
       	    $("#expiration_time").val(expiration_time);
       })
	</script>
</body>
</html>